#!/bin/bash

# 创建主要目录结构
mkdir -p cmd/voluxd
mkdir -p internal/{api/{handlers,middleware,routes},domain,service,store}
mkdir -p pkg/{spdk,utils}
mkdir -p api/openapi
mkdir -p configs
mkdir -p deployments
mkdir -p docs

# 移动现有文件到新位置
mv controllers/* internal/api/handlers/
mv models/* internal/domain/
mv services/* internal/service/
mv utils/* pkg/utils/
mv conf/* configs/
mv swagger/* api/openapi/

# 创建新的main.go
cat > cmd/voluxd/main.go << 'EOF'
package main

import (
    "log"
    "volux/internal/api/routes"
    "volux/internal/service"
    "volux/pkg/utils"
)

func main() {
    // 初始化配置
    if err := utils.InitConfig(); err != nil {
        log.Fatalf("Failed to initialize config: %v", err)
    }

    // 初始化服务
    if err := service.InitServices(); err != nil {
        log.Fatalf("Failed to initialize services: %v", err)
    }

    // 启动API服务器
    if err := routes.StartServer(); err != nil {
        log.Fatalf("Failed to start server: %v", err)
    }
}
EOF

# 创建go.mod文件
cat > go.mod << 'EOF'
module volux

go 1.22

require (
    github.com/beego/beego/v2 v2.1.0
    go.etcd.io/etcd/client/v3 v3.5.9
)
EOF

# 创建Makefile
cat > Makefile << 'EOF'
.PHONY: build test clean

build:
	go build -o bin/voluxd cmd/voluxd/main.go

test:
	go test -v ./...

clean:
	rm -rf bin/
EOF
